#ifndef MQTTCLIENT_H
#define MQTTCLIENT_H

#include <QObject>
#include <QtMqtt/qmqttclient.h>

class MqttClient : public QObject
{
    Q_OBJECT
public:
    explicit MqttClient(QString ip, quint16 port, QString user_name, QObject *parent = nullptr);
    QMqttClient *m_client;
    QString clientId;
private:
    void send_message(const QMqttTopicName &topic, const QString &playd);
    void send_message(const QMqttTopicName &topic, const QJsonObject &jsonPlayd);
    QString getTimeStemp();

    bool firstConnect = false;


public:
    // 设置恒定值（阈值）
    void setConstantValue(int farm_id, float co2, float temperature, float humidity, float light_intensity);
    void setConstantValueco2(int farm_id, float co2);

    void getConstantValue(int farm_id);

public slots:
    void new_message(const QByteArray &message, const QMqttTopicName &topic = QMqttTopicName());
    void on_connected();

signals:
    // 获取到当前恒定值后，会发送这个信号
    void achievedConstantValue(int farm_id, float co2, float temperature, float humidity, float light_intensity);

};

#endif // MQTTCLIENT_H
